@extends('layouts.buz.layout', ['header_active' => 'member'])

@section('sidebar')
    @include('layouts.buz.sidebar.member', ['active' => 'privacy'])
@endsection()

@section('content')
    {{--隐私数据--}}
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                查看密钥
            </h4>
        </div>
        <div class="panel-body">
            <form class="form-horizontal member bottom_line" role="form" id="miyaoForm">
                <div class="form-group">
                    <label for="firstname" class="col-sm-3 textRight">商户编码：</label>
                    <div class=" col-xs-10 col-sm-5 col-md-4 col-lg-4">
                       <span>{{$user->code}}</span>
                    </div>
                </div>

                <div class="form-group">
                    <label for="lastname" class="col-sm-3 textRight">验证码：</label>
                    <div class="col-xs-6 col-sm-5 col-md-4 col-lg-4">
                        <input type="text" class="form-control" name="sms_code">
                    </div>
                    <div class="col-xs-6 col-sm-5 col-md-4 col-lg-4">
                        <button type="button" class="btn btn-info" id="SendCode">发送验证码</button>
                    </div>
                </div>
                <div class="form-group">
                    <label for="firstname" class="col-sm-3 textRight">交易密码：</label>
                    <div class=" col-xs-10 col-sm-5 col-md-4 col-lg-4">
                        <input type="password" class="form-control" name="trade_pwd">
                    </div>
                </div>
                <div class="form-group">
                    <label for="firstname" class="col-sm-3 textRight"></label>
                    <div class="col-sm-8">
                        <button type="button" class="btn btn-primary" onclick="showPwd()">查看密钥</button>
                    </div>
                </div>
                <div class="form-group">
                    <label for="firstname" class="col-sm-3 textRight">密钥：</label>
                    <div class=" col-xs-10 col-sm-5 col-md-4 col-lg-4">
                        <input type="text" id="key" class="form-control"  readonly="readonly">
                    </div>
                </div>
            </form>

        </div>
    </div>
    @endsection()
@section('bottom_js')
<script>
    $('#miyaoForm').bootstrapValidator({
        message: '这个值没有被验证',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            trade_pwd: {
                message: '交易密码不能为空',
                validators: {
                    notEmpty: {
                        message: '交易密码不能为空'
                    }

                }
            },
            sms_code: {
                message: '手机验证码不能为空',
                validators: {
                    notEmpty: {
                        message: '手机验证码不能为空'
                    }

                }
            }
        }
    });
    $("#SendCode").click(function(){
        var that = $(this);
        $.ajax({
            url: "/api/tool/sms",
            data: {type: 5},
            type: 'post',
            success:function(data){
                if(data.code == 0){
                    setTime(that);
                    showMsg("发送成功");
                }else {
                    showMsg(data.message);
                }
            }
        });
    });
    function showPwd(){
        var bootstrapValidator = $('#miyaoForm').data("bootstrapValidator");
        bootstrapValidator.validate();
        if(bootstrapValidator.isValid()){
            var data = $("#miyaoForm").serialize();
            console.log(data);
            $.ajax({
                url: "/api/profile/viewkey",
                data: data,
                type: 'post',
                success:function(data){
                    if(filterAjaxData(data)){
                       $('#key').val(data.data.key);
//                    }else {
//                        showMsg(data.message);
                    }

                }

            });
        }
    }
</script>
@endsection()
